home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / 3D Additions 1.7 / 3D Additions / 3DDrawingUtils.cp < prev    next >
Encoding:
Text File  |  1995-10-09  |  7.6 KB  |  309 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. // 3DDrawingUtils.cp  ©1995 J. Rodden, DD/MF & Associates. All rights reserved
  3. // ===========================================================================
  4. // C++ wrapper class for 3D drawing utilities.
  5. // Dependent on PPlant UDrawingUtils
  6. //
  7. // This class acts solely as a wrapper class for the lower level, ANSI C,
  8. // routines in 3DUtilities. This class takes care of drawing to different 
  9. // bit depths.
  10. //
  11. // This source code is loosely based on and heavily inspired by source code
  12. // by James W. Osborne, copyright (c) 1993, Apple Computer.
  13.  
  14. #include "3DDrawingUtils.h"
  15. #include "3DAttachments.h"
  16.  
  17. #include <LWindow.h>
  18.  
  19.  
  20. // ===========================================================================
  21. // • St3DPenState                                                St3DPenState •
  22. // ===========================================================================
  23.  
  24. St3DPenState::St3DPenState()
  25. {
  26.     PenState    the3DPnState;
  27.           
  28.     ::GetPenState(&mPenState);
  29.     
  30.     ::Get3DPenState(&the3DPnState);
  31.     ::SetPenState(&the3DPnState);
  32. }
  33.  
  34.  
  35. // ===========================================================================
  36. // • U3DDrawingUtils                                         U3DDrawingUtils •
  37. // ===========================================================================
  38.  
  39. void U3DDrawingUtils::MakeWindow3D(LWindow* inWindow)
  40. {
  41.     const Pattern black = {0xFFFFFFF0};
  42.     PenState thePenState;
  43.     thePenState.pnSize.h = 1;
  44.     thePenState.pnSize.v = 1;
  45.     thePenState.pnMode = srcCopy;
  46.     thePenState.pnPat = black;
  47.  
  48.     inWindow->AddAttachment(new C3DPanelAttachment(&thePenState));
  49. }
  50.     
  51.  
  52. // ===========================================================================
  53. // ===========================================================================
  54. void U3DDrawingUtils::Paint3DBkgnd(const  Rect* inRect)
  55. {
  56.     RGBColor bkgndClr;
  57.     U3DDrawingUtils::Get3DBackColor(&bkgndClr);
  58.   ::RGBForeColor(&bkgndClr);
  59.   ::PaintRect(inRect);
  60. }
  61.  
  62.  
  63. // ===========================================================================
  64. // ===========================================================================
  65. void    U3DDrawingUtils::Draw3DHLine ( short vpos, short h1, short h2,
  66.                                        const RGBColor *inULColor,
  67.                                        const RGBColor *inLRColor)
  68. {
  69.     PenState thePenState;
  70.     Get3DPenState(&thePenState);
  71.     
  72.     Rect    theRect;
  73.     Point    pt1 = {    vpos, h1},
  74.             pt2 = {    vpos + 2*thePenState.pnSize.v, h2};
  75.     
  76.     ::Pt2Rect( pt1, pt2, &theRect);
  77.     
  78.     St3DDeviceLoop    theLoop(theRect);
  79.     
  80.     while (theLoop.Next()) {
  81.         if (theLoop.CurrentDeviceIs3DCapable()) {
  82.           ::Draw3DHLine ( vpos, h1, h2, inULColor, inLRColor);
  83.         } else {
  84.           St3DPenState    thePnState;
  85.  
  86.           ::MoveTo( h1, vpos);
  87.           ::LineTo( h2, vpos);
  88.           ::BWShadowLine( h1, vpos+thePenState.pnSize.v,
  89.                             h2, vpos+thePenState.pnSize.v);
  90.         }
  91.     }
  92. }
  93.     
  94. // ===========================================================================
  95. void    U3DDrawingUtils::Draw3DVLine ( short hpos, short v1, short v2,
  96.                                        const RGBColor *inULColor,
  97.                                        const RGBColor *inLRColor)
  98. {
  99.     PenState thePenState;
  100.     Get3DPenState(&thePenState);
  101.     
  102.     Rect    theRect;
  103.     Point    pt1 = {    v1,    hpos},
  104.             pt2 = {    v2,    hpos + 2*thePenState.pnSize.h};
  105.     
  106.     ::Pt2Rect( pt1, pt2, &theRect);
  107.     
  108.     St3DDeviceLoop    theLoop(theRect);
  109.     
  110.     while (theLoop.Next()) {
  111.         if (theLoop.CurrentDeviceIs3DCapable()) {
  112.           ::Draw3DVLine ( hpos, v1, v2, inULColor, inLRColor);
  113.         } else {
  114.           St3DPenState    thePnState;
  115.  
  116.           ::MoveTo( hpos, v1);
  117.           ::LineTo( hpos, v2);
  118.           ::BWShadowLine( hpos+thePenState.pnSize.v, v1,
  119.                             hpos+thePenState.pnSize.v, v2);
  120.         }
  121.     }
  122. }
  123.     
  124.  
  125. // ===========================================================================
  126. // ===========================================================================
  127. void    U3DDrawingUtils::DrawCLine ( const RGBColor *inColor, short h1, short v1,
  128.                                                               short h2, short v2)
  129. {
  130.   ::MoveTo( h1, v1);
  131.     CLineTo ( inColor, h2, v2);
  132. }
  133.     
  134. // ===========================================================================
  135. void    U3DDrawingUtils::CLineTo ( const RGBColor *inColor, short h, short v)
  136. {
  137.     Rect    theRect;
  138.     Point    pt1 = { v, h},
  139.             pt2 = { v+2, h+2};
  140.     
  141.     ::Pt2Rect( pt1, pt2, &theRect);
  142.     
  143.     St3DDeviceLoop    theLoop(theRect);
  144.     
  145.     while (theLoop.Next()) {
  146.         if (theLoop.CurrentDeviceIs3DCapable()) {
  147.           ::CLineTo ( inColor, h, v);
  148.         } else {
  149.           ::LineTo( h, v);
  150.         }
  151.     }
  152. }
  153.     
  154. // ===========================================================================
  155. // ===========================================================================
  156.  
  157. void     U3DDrawingUtils::DoDeviceLoop(
  158.     RectArgProc Draw3DEffect,
  159.     RectArgProc DrawPlainEffect,
  160.     const Rect* inRect)
  161. {
  162.     St3DDeviceLoop    theLoop(*inRect);
  163.     
  164.     while (theLoop.Next()) {
  165.         if (theLoop.CurrentDeviceIs3DCapable()) {
  166.           Draw3DEffect(inRect);
  167.         } else {
  168.           St3DPenState    thePnState;
  169.  
  170.           DrawPlainEffect(inRect);
  171.         }
  172.     }
  173. }
  174.  
  175. // ===========================================================================
  176.  
  177. void     U3DDrawingUtils::DoDeviceLoop(
  178.     Rect2RGBColorArgProc    Draw3DEffect,
  179.     RectArgProc                DrawPlainEffect,
  180.     const Rect*                inRect,
  181.     const RGBColor*            inColor1,
  182.     const RGBColor*            inColor2)
  183. {
  184.     St3DDeviceLoop    theLoop(*inRect);
  185.     
  186.     while (theLoop.Next()) {
  187.         if (theLoop.CurrentDeviceIs3DCapable()) {
  188.           Draw3DEffect( inRect, inColor1, inColor2);
  189.         } else {
  190.           St3DPenState    thePnState;
  191.  
  192.           DrawPlainEffect(inRect);
  193.         }
  194.     }
  195. }
  196.  
  197. // ===========================================================================
  198.  
  199. void     U3DDrawingUtils::DoDeviceLoop(
  200.     Rect2RGBColorBooleanArgProc Draw3DEffect,
  201.     RectArgProc                    DrawPlainEffect,
  202.     const Rect*                    inRect,
  203.     const RGBColor*                inColor1,
  204.     const RGBColor*                inColor2,
  205.     const Boolean                 inFrameIt)
  206. {
  207.     St3DDeviceLoop    theLoop(*inRect);
  208.     
  209.     while (theLoop.Next()) {
  210.         if (theLoop.CurrentDeviceIs3DCapable()) {
  211.           Draw3DEffect( inRect, inColor1, inColor2, inFrameIt);
  212.         } else {
  213.           St3DPenState    thePnState;
  214.  
  215.           DrawPlainEffect(inRect);
  216.         }
  217.     }
  218. }
  219.  
  220. // ===========================================================================
  221.  
  222. void     U3DDrawingUtils::DoDeviceLoop(
  223.     Rect3RGBColorBooleanArgProc    Draw3DEffect,
  224.     RectArgProc                    DrawPlainEffect,
  225.     const Rect*                    inRect,
  226.     const RGBColor*                inColor1,
  227.     const RGBColor*                inColor2,
  228.     const RGBColor*                inColor3,
  229.     const Boolean                inFrameIt)
  230. {
  231.     St3DDeviceLoop    theLoop(*inRect);
  232.     
  233.     while (theLoop.Next()) {
  234.         if (theLoop.CurrentDeviceIs3DCapable()) {
  235.           Draw3DEffect( inRect, inColor1, inColor2, inColor3, inFrameIt);
  236.         } else {
  237.           St3DPenState    thePnState;
  238.  
  239.           DrawPlainEffect(inRect);
  240.         }
  241.     }
  242. }
  243.  
  244. // ===========================================================================
  245.  
  246. void     U3DDrawingUtils::DoDeviceLoopHLine(
  247.     LineArgProc    Draw3DEffect,
  248.     short        vpos,
  249.     short        h1,
  250.     short        h2)
  251. {
  252.     Rect    theRect;
  253.     Point    pt1 = {    vpos,    h1},
  254.             pt2 = {    vpos+2,    h2};
  255.     
  256.     ::Pt2Rect( pt1, pt2, &theRect);
  257.     
  258.     St3DDeviceLoop    theLoop(theRect);
  259.     
  260.     while (theLoop.Next()) {
  261.         if (theLoop.CurrentDeviceIs3DCapable()) {
  262.             Draw3DEffect( vpos, h1, h2);
  263.         } else {
  264.           St3DPenState    thePnState;
  265.  
  266.           ::MoveTo( h1, vpos);
  267.           ::LineTo( h2, vpos);
  268.         }
  269.     }
  270. }
  271.  
  272. // ===========================================================================
  273.  
  274. void     U3DDrawingUtils::DoDeviceLoopVLine(
  275.     LineArgProc    Draw3DEffect,
  276.     short        hpos,
  277.     short        v1,
  278.     short        v2)
  279. {
  280.     Rect    theRect;
  281.     Point    pt1 = {    v1,    hpos},
  282.             pt2 = {    v2,    hpos+2};
  283.     
  284.     ::Pt2Rect( pt1, pt2, &theRect);
  285.     
  286.     St3DDeviceLoop    theLoop(theRect);
  287.     
  288.     while (theLoop.Next()) {
  289.         if (theLoop.CurrentDeviceIs3DCapable()) {
  290.              Draw3DEffect( hpos, v1, v2);
  291.         } else {
  292.           St3DPenState    thePnState;
  293.  
  294.           ::MoveTo( hpos, v1);
  295.           ::LineTo( hpos, v2);
  296.         }
  297.     }
  298. }
  299.  
  300.  
  301. // ===========================================================================
  302. // ===========================================================================
  303.  
  304. void    U3DDrawingUtils::DoFrameOval(const Rect* inRect)
  305.     { ::FrameOval(inRect); }
  306.  
  307. void    U3DDrawingUtils::DoFrameRect(const Rect* inRect)
  308.     { ::FrameRect(inRect); }
  309.